﻿@{
    ViewBag.Title = "SetBGK";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>   
    <style>
        table {
        }
            table tr {
            }
                table tr td {
                    text-align: center;
                    width:160px !important;
                }
    </style>
}

<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
    <table style="width:100%;">
        <tr>
            <td style="width:100%;text-align:left !important;">
                <a class="mini-button" id="save" name="save" iconCls="icon-save" onclick="saveData" plain="true">保存</a>
                 <span class="separator"></span>
                <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>       
</div>

<table style= "width:640px; height:310px; margin-top:20px;">
    <tr style="height:100px;">
        <td>
                    <img id="Image1" src="../Content/Images/MemberBGK/1.png" Width="120" height="80" /> 
        </td>
        <td>
                    <img id="Image2" src="../Content/Images/MemberBGK/2.png" Width="120" height="80" /> 
        </td>
        <td>
                    <img id="Image3" src="../Content/Images/MemberBGK/3.png" Width="120" height="80" /> 
        </td>
        <td>
                    <img id="Image4" src="../Content/Images/MemberBGK/4.png" Width="120" height="80" />
        </td>            
    </tr>
    <tr style="height:30px;">
        <td>    
            <div id="ck1" name="ck1"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="背景1" onclick="setBKclick(1)"></div>
        </td>
        <td>
            <div id="ck2" name="ck2"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="背景2" onclick="setBKclick(2)"></div>
        </td>
        <td>
            <div id="ck3" name="ck3"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="背景3" onclick="setBKclick(3)"></div>
        </td>
        <td>
            <div id="ck4" name="ck4"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="背景4" onclick="setBKclick(4)"></div>
        </td>
    </tr>
    <tr>
        <td colspan="4" style="height:50px;">&nbsp;</td>
    </tr>
    <tr style="height:100px;">
        <td>
            <img id="Image5" src="../Content/Images/MemberBGK/5.png" Width="120" height="80" style="padding-bottom: 23px;" /> 
        </td>
        <td>
            <img id="Image6" src="../Content/Images/MemberBGK/6.png" Width="120" height="80" style="padding-bottom: 23px;" /> 
        </td>
        <td>
            <img id="Image7" src="../Content/Images/MemberBGK/7.png" Width="120" height="80" style="padding-bottom: 23px;"/> 
        </td>
        <td>
            <img id="Image8" src="~/Content/Images/NoImage.jpg" Width="120" height="80" /> 
            </br><input id="myfile" type="file" accept=".jpg,.png" style="width: 168px;">
        </td>
    </tr>
    <tr style="height:30px;">
        <td>
            <div id="ck5" name="ck5"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="背景5" onclick="setBKclick(5)"></div>
        </td>
        <td>
            <div id="ck6" name="ck6"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="背景6" onclick="setBKclick(6)"></div>
        </td>
        <td>
            <div id="ck7" name="ck7"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="背景7" onclick="setBKclick(7)"></div>
        </td>
        <td>
            <div id="ck8" name="ck8"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" text="自定义" onclick="setBKclick(8)"></div>
            <input type="text" id="FLogoUrl" name="FLogoUrl" class="mini-hidden" enabled="false" required="true" width="200px" />
        </td>
    </tr>
</table>
<input id="FName" type="hidden" class="mini-hidden" />


<script>
    mini.parse();
    
    var BGKindex = 0;
    var Edit = 0;

    function FormShown() { }

    $(function () {
        $("#myfile").change(function () {
            //if (Edit == 0) return;
            var formData = new FormData();
            formData.append("myfile", document.getElementById('myfile').files[0]);
            formData.append("mSystemAppID", parent.window.getSystemAppID());
            debugger;
            $.ajax({
                url: "/Upload/UploadFile",
                type: "post",
                data: formData,
                contentType: false,
                processData: false,
                success: function (res) {
                    if (res.status == 1) {
                        $("#Image8").attr("src", res.path);
                        mini.get("FLogoUrl").setValue(res.logoUrl);

                    }
                }
            });
        });
    });

    function SetInfoData(data) {
        BGKindex = data.Index;
        Edit = data.Edit;
        //if (Edit == 0) setCBoxEnabled(false);
        setCheckBox(data.Index);
        $("#Image8").attr("src", data.FMiniUploadBGK);
        mini.get("FLogoUrl").setValue(data.FMiniUploadBGK);
        mini.get("FName").setValue(data.FName);
    }

    function setCheckBox(index) {
        switch (index) {
            case 1: mini.get("ck1").setValue(true); break;
            case 2: mini.get("ck2").setValue(true); break;
            case 3: mini.get("ck3").setValue(true); break;
            case 4: mini.get("ck4").setValue(true); break;
            case 5: mini.get("ck5").setValue(true); break;
            case 6: mini.get("ck6").setValue(true); break;
            case 7: mini.get("ck7").setValue(true); break;
            case 8: mini.get("ck8").setValue(true); break;
        }
    }

    function setCBoxEnabled(b) {
        mini.get("ck1").setEnabled(b);
        mini.get("ck2").setEnabled(b);
        mini.get("ck3").setEnabled(b);
        mini.get("ck4").setEnabled(b);
        mini.get("ck5").setEnabled(b);
        mini.get("ck6").setEnabled(b);
        mini.get("ck7").setEnabled(b);
        mini.get("ck8").setEnabled(b);
    }

    function setcheckbox(b) {
        mini.get("ck1").setValue(b);
        mini.get("ck2").setValue(b);
        mini.get("ck3").setValue(b);
        mini.get("ck4").setValue(b);
        mini.get("ck5").setValue(b);
        mini.get("ck6").setValue(b);
        mini.get("ck7").setValue(b);
        mini.get("ck8").setValue(b);
    }

    function setBKclick(index) {        
        BGKindex = index;
        setcheckbox(false);
        setCheckBox(index);
    }

    function saveData() {
        mini.get("save").setEnabled(false);
        var datastr = '[{"FName":"'+mini.get("FName").getValue()+'","FMiniBGKindex":"' + BGKindex + '","FMiniEdit":"' + Edit
            + '","Image8":"'+mini.get("FLogoUrl").getValue()+'","mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        $.post("saveBGK", { json: datastr }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.get("save").setEnabled(true);
        });
    }
</script>